package com.unieagle.exam.http;

import java.lang.reflect.Type;
import java.util.Map;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.RetryPolicy;
import com.android.volley.VolleyError;

/**
 * Created by guoyao on 2017/9/20.
 */

public class VolleyTask {
    private Class<? extends Request> requestClass = VolleyRequest.GsonGsonRequest.class;

    private int id;
    private Map<String,String> headers;
    private Type responseType;
    private String url;
    private boolean isCache = false;
    private int method = Request.Method.GET;
    private Response.Listener<Object> listener;
    private Response.ErrorListener errorListener;
    private IVolleyListener volleyListener;

    private RetryPolicy polocy;
    private String content;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public Type getResponseType() {
        return responseType;
    }

    public void setResponseType(Type responseType) {
        this.responseType = responseType;
    }

    public int getMethod() {
        return method;
    }

    public void setMethod(int method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public boolean isCache() {
        return isCache;
    }

    public void setCache(boolean cache) {
        isCache = cache;
    }

    public IVolleyListener getVolleyListener() {
        return volleyListener;
    }

    public void setVolleyListener(IVolleyListener l) {
        this.volleyListener = l;
        if(listener == null){
            listener = new Response.Listener<Object>(){
                @Override
                public void onResponse(Object obj) {
                    VolleyTask.this.volleyListener.onComplete(VolleyTask.this, obj);
                }
            };

        }
        if(errorListener == null){
            errorListener = new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    VolleyTask.this.volleyListener.onError(VolleyTask.this, volleyError);
                }
            };
        }
    }

    public Response.Listener<Object> getListener() {
        return listener;
    }

    public Response.ErrorListener getErrorListener() {
        return errorListener;
    }

    public RetryPolicy getPolocy() {
        return polocy;
    }

    public void setPolocy(RetryPolicy polocy) {
        this.polocy = polocy;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Class<? extends Request> getRequestClass() {
        return requestClass;
    }

    public void setRequestClass(Class<? extends Request> requestClass) {
        this.requestClass = requestClass;
    }
}
